
//
//  UISearchBar+CPJSearchBar.m
//  成品家
//
//  Created by YYY on 2017/3/7.
//  Copyright © 2017年 成品家（北京）网路科技有限公司. All rights reserved.
//

#import "UISearchBar+CPJSearchBar.h"

@implementation UISearchBar (CPJSearchBar)
//设置UISearchBar属性
-(void)setSearchBarAttribute:(UIColor *)textColor fontSize:(CGFloat)fontSize placeHolderStr:(NSString *)placeHolderStr placeHolderColor:(UIColor *)placeHolderColor placeHolderFontSize:(CGFloat)placeHolderFontSize searchStr:(NSString *)searchStr
{
    //设置搜索Icon
    [self setImage:[UIImage imageNamed:searchStr]
         forSearchBarIcon:UISearchBarIconSearch
                    state:UIControlStateNormal];
    self.searchBarStyle = UISearchBarStyleDefault;
    self.translucent = YES;
    
    //系统自带文本框
    UITextField * searchField = [self valueForKey:@"_searchField"];
    //清除按钮
    searchField.clearButtonMode = UITextFieldViewModeWhileEditing;
    //自动纠正
    self.autocorrectionType = UITextAutocorrectionTypeNo;
    //自动大写
    self.autocapitalizationType = UITextAutocapitalizationTypeNone;
    //设置字体颜色
    searchField.textColor = textColor;
    searchField.font = [UIFont systemFontOfSize:fontSize];
    
    self.placeholder = placeHolderStr;
    //修改placeholder字体的颜色和大小
    [searchField setValue:placeHolderColor forKeyPath:@"_placeholderLabel.textColor"];
    [searchField setValue:[UIFont systemFontOfSize:placeHolderFontSize] forKeyPath:@"_placeholderLabel.font"];
    //给searchBar中的textField添加背景图
    //[self setSearchFieldBackgroundImage:[UIImage imageNamed:@"a"] forState:UIControlStateNormal];
    
    //设置搜索框textField的位置,其他控件位置不改变
    //    mySearchBar.searchFieldBackgroundPositionAdjustment = UIOffsetMake(50, 0);
    //    //设置textField里面文字在field中的位置
    //    mySearchBar.searchTextPositionAdjustment = UIOffsetMake(50, 0);
}
@end
